//
//  MyDepositCell.m
//  CBT
//
//  Created by Mr.Zhang on 2018/11/21.
//  Copyright © 2018 Mr.Zhang. All rights reserved.
//

#import "MyDepositCell.h"

@interface MyDepositCell()

@property (nonatomic, strong) UIView *rootView;
@property (nonatomic, strong) UIImageView *rootLayerView;
@property (nonatomic, strong) UIImageView *iconImageView;
@property (nonatomic, strong) UIImageView *roundIconImageView;

@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UIView *lineView;

@property (nonatomic, strong) UILabel *saveTimeLabel;
@property (nonatomic, strong) UILabel *savePrincipalLabel;
@property (nonatomic, strong) UILabel *incomeLabel;
@property (nonatomic, strong) UILabel *extractIncomeLabel;

@property (nonatomic, strong) UILabel *rightSaveTimeLabel;
@property (nonatomic, strong) UILabel *rightSavePrincipalLabel;
@property (nonatomic, strong) UILabel *rightIncomeLabel;
@property (nonatomic, strong) UILabel *rightSExtractIncomeLabel;

@property (nonatomic, strong) UIImageView *rootImageView;

@end

@implementation MyDepositCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor whiteColor];
        [self initSubViews];
    }
    return self;
}

//续投
-(void)setModel:(MyInvestListItemModel *)model
{
    _model = model;
    
    _rightSaveTimeLabel.text = [NSString getShowDateMonthDayWithTime:[model.date longLongValue]];
    
    _nameLabel.text = model.coinSymbol;
    _rightSavePrincipalLabel.text = model.capital;
    
    _rightIncomeLabel.text = [DecimalNumberTool formatNumberWithString:model.totalIncome isAssets:NO];
    _rightSExtractIncomeLabel.text = [DecimalNumberTool formatNumberWithString:model.yesterdayIncome isAssets:NO];
    
    [_iconImageView lf_setImageURL:[NSString stringWithFormat:@"%@/%@",kBaseURL_PICSTATIC,model.coinPic]];
}

- (void)initSubViews
{
    self.backgroundColor = [UIColor clearColor];
    
    _rootView = [[UIView alloc]init];
    _rootView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:_rootView];
    
    _rootImageView = [[UIImageView alloc]init];
    _rootImageView.image = [UIImage imageNamed:@"shuiyin"];
    [_rootView addSubview:_rootImageView];
    
    _rootLayerView = [[UIImageView alloc]init];
    _rootLayerView.image = [UIImage resizableImageWithName:@"huijiao"];
    [self.contentView addSubview:_rootLayerView];
    
    _iconImageView = [[UIImageView alloc]init];
    _iconImageView.backgroundColor = DefaultImageViewBgColor;
    _iconImageView.clipsToBounds   = YES;
    _iconImageView.contentMode     = UIViewContentModeScaleAspectFill;
    [_rootView addSubview:_iconImageView];
    
    _roundIconImageView = [[UIImageView alloc]init];
    _roundIconImageView.image = [UIImage imageNamed:@"white_bg"];
    [_rootView addSubview:_roundIconImageView];
    
    _nameLabel = [[UILabel alloc]init];
    _nameLabel.font = [UIFont systemFontOfSize:18];
    _nameLabel.textColor = UIColorFromRGB(0x333333);
    [_rootView addSubview:_nameLabel];
    
    _lineView =  [[UIView alloc]init];
    _lineView.backgroundColor = LineViewBgColor;
    [_rootView addSubview:_lineView];
 
    _saveTimeLabel = [[UILabel alloc]init];
    _saveTimeLabel.text = kLocalizedString(@"开启时间:", nil);
    _saveTimeLabel.font = [UIFont systemFontOfSize:14];
    _saveTimeLabel.textColor = UIColorFromRGB(0x333333);
    [_rootView addSubview:_saveTimeLabel];
    
    _savePrincipalLabel = [[UILabel alloc]init];
    _savePrincipalLabel.text =  kLocalizedString(@"挖矿数量:", nil);
    _savePrincipalLabel.font = [UIFont systemFontOfSize:14];
    _savePrincipalLabel.textColor = UIColorFromRGB(0x333333);
    [_rootView addSubview:_savePrincipalLabel];
    
    _incomeLabel = [[UILabel alloc]init];
    _incomeLabel.text = kLocalizedString(@"累计收益:", nil);
    _incomeLabel.font = [UIFont systemFontOfSize:14];
    _incomeLabel.textColor = UIColorFromRGB(0x333333);
    [_rootView addSubview:_incomeLabel];
    
    _extractIncomeLabel = [[UILabel alloc]init];
    _extractIncomeLabel.text = kLocalizedString(@"昨日收益:", nil);
    _extractIncomeLabel.font = [UIFont systemFontOfSize:14];
    _extractIncomeLabel.textColor = UIColorFromRGB(0x333333);
    [_rootView addSubview:_extractIncomeLabel];
    
    _rightSaveTimeLabel = [[UILabel alloc]init];
    _rightSaveTimeLabel.font = [UIFont systemFontOfSize:14];
    _rightSaveTimeLabel.textColor = UIColorFromRGB(0x333333);
    [_rootView addSubview:_rightSaveTimeLabel];
    
    _rightSavePrincipalLabel = [[UILabel alloc]init];
    _rightSavePrincipalLabel.font = [UIFont systemFontOfSize:14];
    _rightSavePrincipalLabel.textColor = UIColorFromRGB(0x333333);
    [_rootView addSubview:_rightSavePrincipalLabel];
    
    _rightIncomeLabel = [[UILabel alloc]init];
    _rightIncomeLabel.font = [UIFont systemFontOfSize:14];
    _rightIncomeLabel.textColor = UIColorFromRGB(0x333333);
    [_rootView addSubview:_rightIncomeLabel];
    
    _rightSExtractIncomeLabel = [[UILabel alloc]init];
    _rightSExtractIncomeLabel.font = [UIFont systemFontOfSize:14];
    _rightSExtractIncomeLabel.textColor = UIColorFromRGB(0x333333);
    [_rootView addSubview:_rightSExtractIncomeLabel];
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    __weak typeof(self) weakSelf = self;
    [_rootView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.top.mas_equalTo(5);
        make.height.mas_equalTo(200);
    }];
    
    [_rootLayerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.top.mas_equalTo(5);
        make.height.mas_equalTo(200);
    }];
    
    [_iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(35);
        make.top.mas_equalTo(10);
        make.left.mas_equalTo(15);
    }];
    
    [_roundIconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(35);
        make.top.mas_equalTo(10);
        make.left.mas_equalTo(15);
    }];
    
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.iconImageView.mas_right).offset(15);
        make.top.height.mas_equalTo(18);
        make.width.mas_equalTo(40);
    }];
    
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(1);
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(weakSelf.iconImageView.mas_bottom).offset(10);
    }];
    
    [_rootImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.top.mas_equalTo(weakSelf.lineView.mas_bottom).offset(30);
        make.width.height.mas_equalTo(100);
    }];
    
    [_saveTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(16);
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(weakSelf.lineView.mas_bottom).offset(10);
    }];
    
    [_savePrincipalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(16);
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(weakSelf.saveTimeLabel.mas_bottom).offset(10);
    }];
    
    [_incomeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(16);
        make.left.mas_equalTo(15);
make.top.mas_equalTo(weakSelf.savePrincipalLabel.mas_bottom).offset(12);
    }];
    
    [_extractIncomeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(16);
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(weakSelf.incomeLabel.mas_bottom).offset(10);
    }];
    
    [_rightSaveTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(16);
        make.left.mas_equalTo(weakSelf.saveTimeLabel.mas_right).offset(5);
        make.top.mas_equalTo(weakSelf.lineView.mas_bottom).offset(10);
    }];
    
    [_rightSavePrincipalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(16);
    make.left.mas_equalTo(weakSelf.savePrincipalLabel.mas_right).offset(5);
        make.top.mas_equalTo(weakSelf.saveTimeLabel.mas_bottom).offset(10);
    }];
    
    [_rightIncomeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(16);
        make.left.mas_equalTo(weakSelf.incomeLabel.mas_right).offset(5);
make.top.mas_equalTo(weakSelf.savePrincipalLabel.mas_bottom).offset(13);
    }];
    
    [_rightSExtractIncomeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(16);
    make.left.mas_equalTo(weakSelf.extractIncomeLabel.mas_right).offset(5);
    make.top.mas_equalTo(weakSelf.rightIncomeLabel.mas_bottom).offset(10);
    }];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end
